package parabullgame;

import org.lwjgl.input.Mouse;
import java.awt.Color;

public class GuiControlWindow extends GuiControlBase {
    boolean beingDragged;
    int dragX;
    int dragY;
    
    public GuiControlWindow(int x,int y,int w,int h) {
        super(x,y,w,h);
        beingDragged = false;
        
        addChild(new GuiControlButtonClose(w-18,2));
    }
    public void draw(int offsetX, int offsetY) {
        DrawUtil.guiRect(offsetX,offsetY,width,height,Color.gray,false);
        DrawUtil.guiRect(offsetX,offsetY,width,20,color,false);
    }
    public void mouseClick(int button, boolean pressed, int x, int y) {
        if (button == 0 && y < 20 && pressed) {
            beingDragged = true;
            dragX = x;
            dragY = y;
        }
    }
    public void think(int mouseX, int mouseY) {
        if (beingDragged) {
            if (!Mouse.isButtonDown(0)) {
                beingDragged = false;
            }
            posX = posX+mouseX-dragX;
            posY = posY+mouseY-dragY;
        }
    }
}